package edu.towson.forensics.securephone;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

public class ProvidedFunctions {
	
	protected static boolean chkKeyLock(Key KeyName, String KeyValue)
	{
		switch (KeyName)
		{
		//check the stored value of PC MAC with stored value
		case phoneMacAddress:
			return KeyValue.equals("f8:7b:7a:17:a2:d3");
		
		//check name of PC
		case imei:
			return KeyValue.equals("PhoneIMEI");
			
		default:
			return false;
		}
		
	}
	
	protected final static String pcMacAddress()
	{			   
				InetAddress ip=null;
				StringBuilder sb =null;
				NetworkInterface network =null;
				try {
					
					ip = InetAddress.getLocalHost();
					System.out.println("Current IP address : " + ip.getHostAddress());
			 
					if (NetworkInterface.getByInetAddress(ip)!=null)
						network =NetworkInterface.getByInetAddress(ip);
					else
						network =NetworkInterface.getByName("eth0");
					
				try{
					byte[] mac = network.getHardwareAddress();

					sb = new StringBuilder();
					for (int i = 0; i < mac.length; i++) {
						sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));		
					}
					System.out.println(sb.toString());
				}
				catch(NullPointerException e)
				{
					System.out.println(e.getMessage());
					return null;
				}
				
				} catch (UnknownHostException e) {			 
					e.printStackTrace();	
					return null;
				} catch (SocketException e){			 
					e.printStackTrace();
					return null;
				}
		return sb.toString();		
	}
	
	//TODO would provide same ID every time based on same seed
	protected final static String UUID()
	{
	//	UUID uuid=new java.util.UUID(mostSigBits, leastSigBits)
		return null;
	}
	
	// TODO: Find a list of devices and add and remove based on connection event
	protected static boolean listedDevices(String deviceId)
	{
		return false;
	}
	
	protected final static void UnSecurePhone(){
		System.out.println("Phone is Unsecure");
	}
	
	protected final static void NotSecurePhone(){
		System.out.println("Phone is not SecurePhone");
	}
}
